﻿using System.Diagnostics;
using System.Linq;
using Best.SmartCms.Config;
using Best.SmartCms.Core.Utility;
using Best.SmartCms.Dto;
using Microsoft.AspNetCore.Mvc;
using Best.SmartCms.Portal.Models;
using Best.SmartCms.Service;
using Microsoft.Extensions.Caching.Memory;

namespace Best.SmartCms.Portal.Controllers
{
    public class NewsController : Controller
    {
        private readonly ChannelGroupService _channelGroupService;
        private readonly ChannelService _channelService;
        private readonly NewsService _newsService;
        private readonly IMemoryCache _cache;
       

        public NewsController(IMemoryCache memoryCache, ChannelGroupService channelGroupService, ChannelService channelService, NewsService newsService)
        {
            _channelGroupService = channelGroupService;
            _channelService = channelService;
            _newsService = newsService;
            _cache = memoryCache;
        }

        [HttpGet]
        public IActionResult NewsList(long id,int pageindex = 1)
        {
            
            var newslist = _newsService.PageList(new NewsListQueryDto
            {
                PageIndex = pageindex,
                PageSize = 10,
                ChannelId = id
            });

            var model = new NewsInfoModel();
            var channel = _channelService.Info(id);
            model.ChannelId = channel.Id;
            model.ChannelName = channel.Name;
            model.ControllerName = channel.ControllerName;
            model.PageData = newslist;

            return View(model);
        }

        [HttpGet]
        public IActionResult ProductList(long id, int p = 1)
        {
            var newslist = _newsService.PageList(new NewsListQueryDto
            {
                PageIndex = p,
                PageSize = 10,
                ChannelId = id
            });

            var model = new NewsInfoModel();
            var channel = _channelService.Info(id);
            model.ChannelId = channel.Id;
            model.ChannelName = channel.Name;
            model.ControllerName = channel.ControllerName;
            model.PageData = newslist;

            return View(model);
        }


        [HttpGet]
        public IActionResult Preview(long id)
        {
            var newsInfo = _newsService.Detail(id);

            return View(newsInfo);
        }
    }
}
